import pygame, credit
from pygame.locals import *
from sys import exit
import os
import menu2
import recorde
import instrucoes
def main(status=1):
    screen_width, screen_height = 900, 600

    pygame.init()

    screen = pygame.display.set_mode((screen_width,screen_height), 0, 32)
    pygame.display.set_caption("MegaBomb")
    pygame.mouse.set_visible(False)
    mira = pygame.image.load("imagens" + os.sep + "cursor.png").convert_alpha()
    ## Sons
    if status == 0:
        
        pygame.mixer.music.load("audio" + os.sep + "pump.mp3")
        pygame.mixer.music.set_volume(0.1)
        pygame.mixer.music.play(-1)
        tocando_musica = True

    sobre_opcao = pygame.mixer.Sound("audio" + os.sep + "sobre_opcao.wav")
    escolhe_opcao = pygame.mixer.Sound("audio" + os.sep + "explosao.wav")
    escolhe_opcao.set_volume(0.5)
    som1, som2, som3 = False, False, False
    ## Botao jogar 
    new_game_buttons = [pygame.image.load("imagens" + os.sep + "jogar" + str(i+1) + ".png").convert_alpha() for i in xrange(3)]
    new_game_button = new_game_buttons[0]
    new_game_size = new_game_button.get_size()
    new_game_pos = (450,300)
    ##Botao instrucoes
    inst_buttons = [pygame.image.load("imagens" + os.sep + "instrucao" + str(i+1) + ".png").convert_alpha() for i in xrange(3)]
    inst_button = inst_buttons[0]
    inst_size = inst_button.get_size()
    inst_pos = (450,350)
    ##Botao recordes
    recorde_buttons = [pygame.image.load("imagens" + os.sep + "recorde" + str(i+1) + ".png").convert_alpha() for i in xrange(3)]
    recorde_button = recorde_buttons[0]
    recorde_size = recorde_button.get_size()
    recorde_pos = (450,400)
    ## Botao creditos
    credit_buttons = [pygame.image.load("imagens" + os.sep + "creditos" + str(i+1) + ".png").convert_alpha() for i in xrange(3)]
    credit_button = credit_buttons[0]
    credit_size = credit_button.get_size()
    credit_pos = (450,450)
    ## Botao sair
    exit_buttons = [pygame.image.load("imagens" + os.sep + "sair" + str(i+1) + ".png").convert_alpha() for i in xrange(3)]
    exit_button = exit_buttons[0]
    exit_size = exit_button.get_size()
    exit_pos = (450,500)

    ## Imagem do fundo
    background = pygame.image.load("imagens" + os.sep + "MegaMenu.jpg").convert()

    pressed = False

    while True:
        for event in pygame.event.get():
            if event.type == QUIT:
                exit()
        ## Mouse 
        mouse_pos = pygame.mouse.get_pos()
        mouse_press = pygame.mouse.get_pressed()
        mouse_pos_mira = (mouse_pos[0], mouse_pos[1])

        ## Jogar
        if new_game_pos[0] <= mouse_pos[0] <= new_game_pos[0] + new_game_size[0] and new_game_pos[1] <= mouse_pos[1] <= new_game_pos[1] + new_game_size[1]:

            new_game_button = new_game_buttons[1]
            

            if mouse_press[0]:
                new_game_button = new_game_buttons[2]
                pressed = True
                escolhe_opcao.play()
                

            if pressed and not mouse_press[0]:
                new_game_button = new_game_buttons[1]
                tocando_musica = False
                inicia = menu2.Menu()
                inicia.executaMenu()

        else:
            new_game_button = new_game_buttons[0]
            som1 = False

        #instrucoes
        if inst_pos[0] <= mouse_pos[0] <= inst_pos[0] + inst_size[0] and inst_pos[1] <= mouse_pos[1] <= inst_pos[1] + inst_size[1]:

            inst_button = inst_buttons[1]
            

            if mouse_press[0]:
                inst_button = inst_buttons[2]
                pressed = True
                escolhe_opcao.play()

            if pressed and not mouse_press[0]:
                inst_button = inst_buttons[1]
                tocando_musica = False
                inicia = menu2.Menu()
                instrucoes.main()

        else:
            inst_button = inst_buttons[0]

        #recorde
        if recorde_pos[0] <= mouse_pos[0] <= recorde_pos[0] + recorde_size[0] and recorde_pos[1] <= mouse_pos[1] <= recorde_pos[1] + recorde_size[1]:

            recorde_button = recorde_buttons[1]
            

            if mouse_press[0]:
                recorde_button = recorde_buttons[2]
                pressed = True
                escolhe_opcao.play()

            if pressed and not mouse_press[0]:
                recorde_button = recorde_buttons[1]
                tocando_musica = False
                recorde.main()

        else:
            recorde_button = recorde_buttons[0]

    

        
        ## Creditos
        if credit_pos[0] <= mouse_pos[0] <= credit_pos[0] + credit_size[0] and credit_pos[1] <= mouse_pos[1] <= credit_pos[1] + credit_size[1]:

            credit_button = credit_buttons[1]
            

            if mouse_press[0]:
                credit_button = credit_buttons[2]
                pressed = True
                escolhe_opcao.play()
                    

            if pressed and not mouse_press[0]:
                credit_button = credit_buttons[1]
                credit.main()

        else:
            credit_button = credit_buttons[0]

        ## Sair
        if exit_pos[0] <= mouse_pos[0] <= exit_pos[0] + exit_size[0] and exit_pos[1] <= mouse_pos[1] <= exit_pos[1] + exit_size[1]:

            exit_button = exit_buttons[1]
            

            if mouse_press[0]:
                exit_button = exit_buttons[2]
                pressed = True
                escolhe_opcao.play()

            if pressed and not mouse_press[0]:
                exit_button = exit_buttons[1]
                exit()

        else:
            exit_button = exit_buttons[0]

        if not mouse_press[0]:
            pressed = False
        ## Atualiza imagens
        screen.blit(background, (0,0))
        screen.blit(inst_button,inst_pos)
        screen.blit(recorde_button,recorde_pos)
        screen.blit(credit_button, credit_pos)
        screen.blit(exit_button, exit_pos)
        screen.blit(new_game_button, new_game_pos)
        screen.blit(mira, mouse_pos_mira)
        

        pygame.display.update()

